﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace NutriLeaf.Phone.Settings
{
    
    public class SettingUtility
    {
        static Settings setting=new Settings();

        //events
        public delegate void GetUserDataCompleted(bool result);
        public static event GetUserDataCompleted GetUserDataCompletedEvent;


        public static void GetUserData()
        {
            AccountService.AccountServiceClient client = new AccountService.AccountServiceClient();
            client.GetUserDataCompleted += new EventHandler<AccountService.GetUserDataCompletedEventArgs>(client_GetUserDataCompleted);
            client.GetUserDataAsync(setting.FacebookAccessToken);
        }

        static void client_GetUserDataCompleted(object sender, AccountService.GetUserDataCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                setting.User = e.Result.user;
                setting.UserProfile = e.Result.profile;
                GetUserDataCompletedEvent(true);
            }
            else
            {
                GetUserDataCompletedEvent(false);
            }
        }
    }
}
